#lang racket


(require "../matrix.rkt"
         "../nodes.rkt"
         "../point.rkt")

(require "parametric-arc.rkt"
         "parametric-circumference.rkt"
         "parametric-helix-line.rkt"
         "parametric-straight-line.rkt")


(provide parametrize)


(define (parametrize-arc node transformation)
  (make-parametric-arc
   transformation
   (arc-node-radius node)
   (arc-node-angle node)))

(define (parametrize-circle node transformation)
  (make-circumference transformation (circle-node-radius node)))

(define (parametrize-helix-2d node transformation)
  (make-helix-line transformation 1 1 1))

(define (parametrize-move node transformation)
  (let ((transformation
         (m*m 
          transformation
          (apply m.translate (list<-point (move-node-position node))))))
    (parametrize-node (move-node-shape node) transformation)))

(define (parametrize-scale node transformation)
  (let ((transformation
         (m*m
          transformation
          (apply m.scale (list<-point (scale-node-scale node))))))
    (parametrize-node (scale-node-shape node) transformation)))

(define (parametrize-node node transformation)
  (cond ((arc-node? node) (parametrize-arc node transformation))
        ((circle-node? node) (parametrize-circle node transformation))
        ((helix-2d-node? node) (parametrize-helix-2d node transformation))
        
        ((move-node? node) (parametrize-move node transformation))
        ((scale-node? node) (parametrize-scale node transformation))
        (else
         (error 'parametric "Unhandled node"))))

(define (parametrize node)
  (parametrize-node node m.identity))